//
//  GMUserAccountViewController.m
//  BeautyFace
//
//  Created by steven on 2016/12/25.
//  Copyright © 2016年 steven. All rights reserved.
//

#import "GMUserAccountViewController.h"
#import "GMChangePasswordViewController.h"

#define kAccountTableViewCellIdentifier @"kAccountTableViewCellIdentifier"

@interface GMUserAccountViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation GMUserAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupContentView];
}

#pragma mark - setup content view
- (void)setupContentView {
    [self.navigationItem setTitle:@"账号安全"];
    [self.view addSubview:self.tableView];
    [self.tableView autoPinEdgesToSuperviewEdges];
}
#pragma mark - Getter for tableview
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = UIColorFromRGB(0xF8F4F4);
        // [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kAccountTableViewCellIdentifier];
    }
    
    return _tableView;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAccountTableViewCellIdentifier];
    }
    
    if (cell) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"登录名";
            NSString *mobile = [[NSUserDefaults standardUserDefaults] objectForKey:@"mobile"];
            cell.detailTextLabel.text = mobile;
        } else {
            cell.textLabel.text = @"修改密码";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    
    return cell;
}

#pragma mark - UITableViewDatasource
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.row == 1) {
        GMChangePasswordViewController *changePasswordViewController = [[GMChangePasswordViewController alloc] init];
        [self.navigationController pushViewController:changePasswordViewController animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
